
package poplar.dp.test;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.protobuf.InvalidProtocolBufferException;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;

import poplar.dp.packet.PoplarProtocol;
import poplar.dp.packet.PoplarProtocol.KeepAlive;
import poplar.dp.packet.PoplarProtocol.ProcessIdent;

public class testPacketBuf {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testSplitter(){	
	}
	
	@Test
	public void testUncompleteHeader(){
		
	}
	
	@Test
	public void testCompleteHeader(){
		
	}
	
	@Test
	public void testUncompleteBody(){
		
	}
	
	@Test
	public void testCompleteBody(){
		
	}
	
	@Test
	public void testCompleteBodyAndUncompleteHeader(){
		
	}
	
	@Test
	public void testCompleteBodyAndCompleteHeader(){
		
	}
	
	@Test
	public void testCompleteBodyAndUncompleteBody(){
		
	}
	
	@Test
	public void testCompleteBodys(){		
	}

	@Test
	public void test() {		
		ProcessIdent.Builder ident = ProcessIdent.newBuilder();
		ident.setId( 50 );
		ident.setName("testName");
		
		byte[] buffer = ident.build().toByteArray();
		
		try{
			ProcessIdent.Builder ident2 = ProcessIdent.newBuilder().mergeFrom( buffer );
			
			assertEquals( ident2.getId(), ident.getId() );
			assertEquals( ident2.getName(), ident2.getName() );
			assertEquals( ident.getPpId(), 1 );
		}
		catch( InvalidProtocolBufferException ipbe ){	
			fail( "error InvalidProtocolBufferException" );
		}
		
		KeepAlive.Builder keep = KeepAlive.newBuilder();
		keep.setArg(1000);
		
		assertEquals( keep.getPpId(), 2 );
	}

}

